package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import com.ruoyi.system.mapper.TbDiscountConditionMapper;
import com.ruoyi.system.domain.TbDiscountCondition;
import com.ruoyi.system.service.ITbDiscountConditionService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 团购规则设置Service业务层处理
 *
 * @author ruoyi
 * @date 2021-02-19
 */
@Service
public class TbDiscountConditionServiceImpl extends ServiceImpl<TbDiscountConditionMapper, TbDiscountCondition> implements ITbDiscountConditionService {


    @Override
    public List<TbDiscountCondition> queryList(TbDiscountCondition tbDiscountCondition) {
        LambdaQueryWrapper<TbDiscountCondition> lqw = Wrappers.lambdaQuery();


            //查询对应的userId
            lqw.eq(TbDiscountCondition::getUserId, SecurityUtils.getLoginUser().getUser().getUserId());

        if (tbDiscountCondition.getDiscountTimeStart() != null){
            lqw.eq(TbDiscountCondition::getDiscountTimeStart ,tbDiscountCondition.getDiscountTimeStart());
        }
        if (tbDiscountCondition.getDiscountTimeEnd() != null){
            lqw.eq(TbDiscountCondition::getDiscountTimeEnd ,tbDiscountCondition.getDiscountTimeEnd());
        }
        if (tbDiscountCondition.getEamestMoney() != null){
            lqw.eq(TbDiscountCondition::getEamestMoney ,tbDiscountCondition.getEamestMoney());
        }
        if (StringUtils.isNotBlank(tbDiscountCondition.getDiscountType())){
            lqw.eq(TbDiscountCondition::getDiscountType ,tbDiscountCondition.getDiscountType());
        }
        if (tbDiscountCondition.getDiscountMoney() != null){
            lqw.eq(TbDiscountCondition::getDiscountMoney ,tbDiscountCondition.getDiscountMoney());
        }
        return this.list(lqw);
    }
}
